var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(t, e) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(t, e) {
        t.__proto__ = e;
    } || function(t, e) {
        for (var n in e) e.hasOwnProperty(n) && (t[n] = e[n]);
    })(t, e);
}, function(t, e) {
    function n() {
        this.constructor = t;
    }
    o(t, e), t.prototype = null === e ? Object.create(e) : (n.prototype = e.prototype, 
    new n());
}), a = this && this.__decorate || function(t, e, n, a) {
    var o, i = arguments.length, r = i < 3 ? e : null === a ? a = Object.getOwnPropertyDescriptor(e, n) : a;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, n, a); else for (var l = t.length - 1; 0 <= l; l--) (o = t[l]) && (r = (i < 3 ? o(r) : 3 < i ? o(e, n, r) : o(e, n)) || r);
    return 3 < i && r && Object.defineProperty(e, n, r), r;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("AdManager"), s = e("LoadManager"), c = cc._decorator, l = c.ccclass, d = c.property, u = function(e) {
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        return t.tag = "base_native", t.root = null, t.iconSprite = null, t.imgSprite = null, 
        t.logoSprite = null, t.titleLabel = null, t.descLabel = null, t.btnLabel = null, 
        t.btnFontSize = 32, t;
    }
    return i(t, e), t.prototype.onLoad = function() {
        GA.isOPPO() || GA.isPlatform(GA.Platform.Vivo) || (this.node.active = !1, this.node.destroy()), 
        this.btnLabel && (this.btnLabel.fontSize = this.btnFontSize);
    }, t.prototype.loadNativeAd = function() {
        return new Promise(function(e, n) {
            0 == r.default.getInstance().nativeAdList.length ? r.default.getInstance().loadNativeAd("test", function(t) {
                t.adList instanceof Array && 0 < t.adList.length ? (console.log("loadNativeAd success", t.adList), 
                r.default.getInstance().nativeAdList = t.adList, e()) : (console.log("loadNativeAd fail", "adList is undefined or length 0"), 
                n());
            }, function() {
                console.log("loadNativeAd fail"), n();
            }) : (console.log("loadNativeAd already", r.default.getInstance().nativeAdList), 
            e());
        });
    }, t.prototype.checkNativeAd = function() {
        var t = this;
        0 == r.default.getInstance().nativeAdList.length ? this.loadNativeAd().then(function() {
            t.showNativeAd();
        }) : this.showNativeAd();
    }, t.prototype.showNativeAd = function() {
        r.default.getInstance().hideAllBanner(), this.root.active = !0, r.default.getInstance().nativeAdItem || (r.default.getInstance().nativeAdItem = r.default.getInstance().nativeAdList[GA.rand(0, r.default.getInstance().nativeAdList.length - 1)]);
        try {
            0 < r.default.getInstance().nativeAdItem.imgUrlList.length && this.loadSprite(r.default.getInstance().nativeAdItem.imgUrlList[GA.rand(0, r.default.getInstance().nativeAdItem.imgUrlList.length - 1)], this.imgSprite), 
            r.default.getInstance().nativeAdItem.logoUrl && this.loadSprite(r.default.getInstance().nativeAdItem.logoUrl, this.logoSprite), 
            r.default.getInstance().nativeAdItem.clickBtnTxt && (this.btnLabel.string = r.default.getInstance().nativeAdItem.clickBtnTxt), 
            r.default.getInstance().nativeAdItem.adId && r.default.getInstance().reportAdShow(r.default.getInstance().nativeAdItem.adId);
        } catch (t) {
            r.default.getInstance().nativeAdItem = null;
        }
    }, t.prototype.onClickAd = function() {
        r.default.getInstance().nativeAdItem && r.default.getInstance().nativeAdItem.adId && (r.default.getInstance().reportAdClick(r.default.getInstance().nativeAdItem.adId), 
        this.root.active = !1, r.default.getInstance().nativeAdList = [], r.default.getInstance().nativeAdItem = null), 
        this.loadNativeAd();
    }, t.prototype.onClickClose = function() {
        this.root.active = !1, r.default.getInstance().nativeAdItem = null;
    }, t.prototype.start = function() {}, t.prototype.loadSprite = function(t, e) {
        t ? s.default.getInstance().loadImage({
            url: t
        }).then(function(t) {
            e && t instanceof cc.Texture2D ? e.spriteFrame = new cc.SpriteFrame(t) : cc.log(t);
        }).catch(function(t) {
            console.error(t);
        }) : console.log("nativeAd loadSprite fail", "无效的url");
    }, a([ d ], t.prototype, "tag", void 0), a([ d(cc.Node) ], t.prototype, "root", void 0), 
    a([ d(cc.Sprite) ], t.prototype, "iconSprite", void 0), a([ d(cc.Sprite) ], t.prototype, "imgSprite", void 0), 
    a([ d(cc.Sprite) ], t.prototype, "logoSprite", void 0), a([ d(cc.Label) ], t.prototype, "titleLabel", void 0), 
    a([ d(cc.Label) ], t.prototype, "descLabel", void 0), a([ d(cc.Label) ], t.prototype, "btnLabel", void 0), 
    a([ l ], t);
}(cc.Component);

n.default = u;